<template>
    <div>
        <van-nav-bar
            title="修改用户个人信息"
            left-text="返回"
            left-arrow
            @click-left="backEvt"
        />     
        <!-- 输入任意文本 -->
        <div class="user">
            <van-field v-model="list.name" label="用户名" />
            <van-field v-model="list.phone" label="手机号" />
            <van-radio-group v-model="list.sex" direction="horizontal">
            <van-radio name="男">男</van-radio>
            <van-radio name="女">女</van-radio>
            </van-radio-group>
            <van-field v-model="list.birthday" label="生日" />        
            <van-field v-model="list.email" label="邮箱" />         
            <van-field v-model="list.address" label="地址" />   
            <van-button round type="info" @click="changeEvt">修改</van-button>                    
        </div>     
    </div>
</template>
<script>
import { changeUserInfoApi, saveUserInfoApi } from '../../axios/loginApi'
export default {
    data() {
        return {
            list:[],
            loading:false,
        }
    },
    created() {
        this.list=this.$store.getters['common/getUserInfo']
    },
    methods: {
        backEvt(){
            this.$dialog.confirm({
                title: '！',
                message: '是否退出',
            }).then(() => {
                this.$router.push('my')
            }).catch(() => {

            });      
        },
        async changeEvt(){
            //节流标志
            if(this.loading){
                return
            }
            let res =await changeUserInfoApi(this.list,this.list.id,localStorage.getItem('autoText'))
                if(res.code===200){
                    this.loading=true
                    console.log(res)
                    this.$toast.success(`用户信息修改成功`)
                }  

            setTimeout(()=>{
                this.loading=false
            })
        },
    },
}
</script>
<style lang="less" scoped>
div{
    width: 100%;
    .el-form{
        width: 90%;
        margin-top: 20px;
    }
    .user{
        .van-radio-group{
            margin-left: 20px;
            margin-top: 10px;
        }
        .van-button{
            width: 70px;
            margin-top: 10px;      
        }
    }
}
</style>